1   // Copyright 2010 The Apache Software Foundation
2   //
3   // Licensed under the Apache License, Version 2.0 (the "License");
4   // you may not use this file except in compliance with the License.
5   // You may obtain a copy of the License at
6   //
7   // http://www.apache.org/licenses/LICENSE-2.0
8   //
9   // Unless required by applicable law or agreed to in writing, software
10  // distributed under the License is distributed on an "AS IS" BASIS,
11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  // See the License for the specific language governing permissions and
13  // limitations under the License.
14  
15  package org.apache.tapestry5.func;
16  
17  import java.util.Arrays;
18  import java.util.List;
19  
20  import org.testng.Assert;
21  
22  public class BaseFuncTest extends Assert
23  {
24  
25      protected Mapper<String, Integer> stringToLength = new Mapper<String, Integer>()
26      {
27          @Override
28          public Integer map(String input)
29          {
30              return input.length();
31          }
32      };
33  
34      protected Mapper<Integer, Boolean> toEven = new Mapper<Integer, Boolean>()
35      {
36          @Override
37          public Boolean map(Integer input)
38          {
39              return evenp.accept(input);
40          }
41      };
42  
43      protected Predicate<Number> evenp = new Predicate<Number>()
44      {
45          @Override
46          public boolean accept(Number object)
47          {
48              return object.longValue() % 2 == 0;
49          };
50      };
51  
52      protected Flow<Integer> filteredEmpty = F.flow(1, 3, 5, 7).filter(evenp);
53  
54      protected <T> void assertFlowValues(Flow<T> actual, T... expected)
55      {
56          assertListsEquals(actual.toList(), expected);
57      }
58  
59      protected <T> void assertListsEquals(List<T> actual, T... expected)
60      {
61          assertEquals(actual, Arrays.asList(expected));
62      }
63  
64      protected void unreachable()
65      {
66          throw new RuntimeException("Should not be reachable.");
67      }
68  
69  }